﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.Data;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.Utils;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraEditors.Controls;
using System.Data.OleDb;

namespace Emergency.Controls
{
    public delegate void FormButtonClickedHandler(object sender, EventArgs e);
    public partial class PlanManagement : DevExpress.XtraEditors.XtraUserControl
    {
        string connString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\datasource.accdb";
       public event FormButtonClickedHandler OnStartClicked =null;
        public PlanManagement()
        {
            InitializeComponent();
        }

        private void btnStart_Click(object sender, EventArgs e)
        {
            if(OnStartClicked!=null)
                this.OnStartClicked(sender, e);
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            FrmNewPlan newPlan = new FrmNewPlan();
            newPlan.ShowDialog();
        }

        private void PlanManagement_Load(object sender, EventArgs e)
        {
            OleDbDataAdapter oda = new OleDbDataAdapter("select * from ExerciseScripts", connString);
            DataSet ds = new DataSet();
            oda.Fill(ds);
            gridControl1.DataSource = ds.Tables[0];

            GridColumn NewColumn = gridView1.Columns.AddField("");
            NewColumn.VisibleIndex = gridView1.Columns.Count;
            NewColumn.UnboundType = UnboundColumnType.String;
            //NewColumn.OptionsColumn.AllowEdit = true;
            NewColumn.Width = 80;
            NewColumn.OptionsColumn.AllowSize = false;
            //NewColumn.MinWidth = 60;

            RepositoryItemButtonEdit riButtonEdit = new RepositoryItemButtonEdit();
            riButtonEdit.TextEditStyle = TextEditStyles.HideTextEditor;
            riButtonEdit.Buttons[0].Kind = ButtonPredefines.Glyph;
            riButtonEdit.Buttons[0].Caption = "启动";
            //riButtonEdit.Buttons[0].Image = ProjectSample.Properties.Resources.PrintPreview;
            riButtonEdit.Buttons[0].ImageAlignment = HorzAlignment.Near;
            riButtonEdit.ButtonClick += new ButtonPressedEventHandler(riButtonEdit_ButtonClick);

            gridControl1.RepositoryItems.Add(riButtonEdit);
            NewColumn.ColumnEdit = riButtonEdit;


            //编辑
            NewColumn = gridView1.Columns.AddField("");
            NewColumn.VisibleIndex = gridView1.Columns.Count;
            NewColumn.UnboundType = UnboundColumnType.String;
            //NewColumn.OptionsColumn.AllowEdit = true;
            NewColumn.Width = 80;
            NewColumn.OptionsColumn.AllowSize = false;
            //NewColumn.MinWidth = 60;

            riButtonEdit = new RepositoryItemButtonEdit();
            riButtonEdit.TextEditStyle = TextEditStyles.HideTextEditor;
            riButtonEdit.Buttons[0].Kind = ButtonPredefines.Glyph;
            riButtonEdit.Buttons[0].Caption = "编辑";
            //riButtonEdit.Buttons[0].Image = ProjectSample.Properties.Resources.PrintPreview;
            riButtonEdit.Buttons[0].ImageAlignment = HorzAlignment.Near;
           

            gridControl1.RepositoryItems.Add(riButtonEdit);
            NewColumn.ColumnEdit = riButtonEdit;

            //删除
            NewColumn = gridView1.Columns.AddField("");
            NewColumn.VisibleIndex = gridView1.Columns.Count;
            NewColumn.UnboundType = UnboundColumnType.String;
            //NewColumn.OptionsColumn.AllowEdit = true;
            NewColumn.Width = 80;
            NewColumn.OptionsColumn.AllowSize = false;
            //NewColumn.MinWidth = 60;

            riButtonEdit = new RepositoryItemButtonEdit();
            riButtonEdit.TextEditStyle = TextEditStyles.HideTextEditor;
            riButtonEdit.Buttons[0].Kind = ButtonPredefines.Glyph;
            riButtonEdit.Buttons[0].Caption = "删除";
            //riButtonEdit.Buttons[0].Image = ProjectSample.Properties.Resources.PrintPreview;
            riButtonEdit.Buttons[0].ImageAlignment = HorzAlignment.Near;


            gridControl1.RepositoryItems.Add(riButtonEdit);
            NewColumn.ColumnEdit = riButtonEdit;
        }

        void riButtonEdit_ButtonClick(object sender, ButtonPressedEventArgs e)
        {
            if (OnStartClicked != null)
                this.OnStartClicked(sender, e);
        }


    }
}
